# -*- coding:utf-8 -*-
'''
@File    :   basic_utils.py
@Time    :   2024/11/17 23:05:10
@Author  :   xiangyu Chen
@Version :   1.0
@Contact :   yu112yu@sina.com
@License :   (C)Copyright 2017-2018, Liugroup-NLPR-CASIA
@Desc    :   None
'''
import yaml
# import glob
from cacheout import Cache

from pathlib import Path


# 读取yaml文件
def read_yaml(filename):
    with open(filename, encoding='utf-8') as f:
        python_obj = yaml.safe_load(f)
    return python_obj


def get_file_path(file_name):

    # files = glob.glob(file_name)  #以项目根目录匹配，取文件名
    #  高级匹配：匹配当前目录及其所有子目录下所有以 .txt 结尾的文件
    path = Path('.')  #项目根目录
    files = list(path.glob(f'**/{file_name}'))  #按文件名匹配目录及子目录下所有的 .txt 文件
    # print("高级匹配的文件：", files)
    file_path = files[0]  #只返回匹配结果的第一个
    return file_path


def get_path(path, file_name):
    return Path(path, file_name)


cache = Cache()


def get_cache(key):
    return cache.get(key)


def set_cache(key, value, ttl=10):
    cache.set(key, value)


if __name__ == '__main__':

    print(get_file_path('login.yaml'))
    # p = Path('.')
    # print(p.absolute())
    # path1 = Path("data")
    # path2 = "file.txt"
    # full_path = path1 / path2
    # path = Path('case', 'file.txt')
    # print(full_path == path)
    # print(full_path.__class__)
    # print(path.__class__)
